package com.itheima.reggie.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.reggie.common.ResultInfo;
import com.itheima.reggie.domain.Setmeal;
import com.itheima.reggie.service.SetmealService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
public class SetmealController {
    @Autowired
    private SetmealService setmealService;

    //套餐列表
    @GetMapping("/setmeal/page")
    public ResultInfo findList(
            @RequestParam(value = "page",defaultValue = "1") Integer pageNum,
           @RequestParam(defaultValue = "10") Integer pageSize,
            String name) {

        Page<Setmeal> page = setmealService.findList(pageNum, pageSize, name);
        return ResultInfo.success(page);
    }

    //添加套餐
    @PostMapping("/setmeal")
    public ResultInfo save(@RequestBody Setmeal setmeal) {
        setmealService.save(setmeal);
        return ResultInfo.success(null);
    }

    //批量删除菜品
    @DeleteMapping("/setmeal")
    public ResultInfo deleteById(@RequestParam("ids") List<Long> ids) {
        setmealService.deleteById(ids);
        return ResultInfo.success(null);

    }

    //回显套餐
    @GetMapping("/setmeal/{id}")
    public ResultInfo findById(@PathVariable("id") Long id) {
        Setmeal setmeal = setmealService.findById(id);
        return ResultInfo.success(setmeal);
    }

    //修改套餐
    @PutMapping("/setmeal")
    public ResultInfo update(@RequestBody Setmeal setmeal) {
        setmealService.update(setmeal);
        return ResultInfo.success(null);
    }

    //批量停售
    @PostMapping("/setmeal/status/{status}")
    public ResultInfo updateStatus(@PathVariable("status") Integer status,@RequestParam("ids") List<Long> ids) {
        setmealService.updateStstus(status, ids);
        return ResultInfo.success(null);
    }

}
